package com.antis.olsl.data.distribution;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.antis.olsl.arouterlib.DataRoutePath;
import com.antis.olsl.base.BaseActivity;
import com.antis.olsl.data.adapter.DistributionInfoFiledListAdapter;
import com.antis.olsl.data.databinding.ActivityDistributionSlipGoodsDetailsBinding;
import com.antis.olsl.data.response.GetDistributionGoodsDetailsData;
import com.antis.olsl.library.bean.DistributionSlipInfo;
import com.antis.olsl.library.bean.GoodsFiledInfo;
import com.antis.olsl.library.utils.StringUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * @ProjectName: ATS_OLSL
 * @Package: com.antis.olsl.activity.purchaseQuery
 * @ClassName: PurchaseSlipGoodsDetailsActivity
 * @Description: 配送单商品详情
 * @Author: 羊琪
 * @CreateDate: 2020/3/30 19:48
 * @UpdateDate: 2020/3/30 19:48
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
@Route(path = DataRoutePath.ACTIVITY_DISTRIBUTION_SLIP_GOODS_DETAIL)
public class DistributionSlipGoodsDetailsActivity extends BaseActivity<ActivityDistributionSlipGoodsDetailsBinding> {

    private ArrayList<GoodsFiledInfo> filedInfos = new ArrayList<>();
    private DistributionInfoFiledListAdapter adapter;
    private boolean fromSalesroom = false;
    private String productId;
    private String purchaseNumber;

    @Override
    protected ActivityDistributionSlipGoodsDetailsBinding getViewBinding() {
        return ActivityDistributionSlipGoodsDetailsBinding.inflate(getLayoutInflater(), baseBinding.getRoot(), true);
    }

    @Override
    protected void initViews() {
        viewBinding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
        adapter = new DistributionInfoFiledListAdapter(filedInfos);
        viewBinding.recyclerView.setAdapter(adapter);
    }

    @Override
    protected void initData() throws IllegalAccessException {
        getDetails();
    }

    /**
     * 获取商品详情
     */
    private void getDetails() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("distributionNumber", purchaseNumber);
        map.put("productId", productId);
        // okHttpClient.postJsonObjectParams(fromSalesroom ? UrlServerConnections.GET_GOODS_DETAILS_FOR_DISTRIBUTION : UrlServerConnections.GET_GOODS_DETAILS_FOR_DISTRIBUTION, map, GetDistributionGoodsDetailsRes.class);
    }

//    @Override
//    public void successResponse(BaseRes baseRes) {
//        if (baseRes instanceof GetDistributionGoodsDetailsRes) {
//            GetDistributionGoodsDetailsRes goodsDetailsRes = (GetDistributionGoodsDetailsRes) baseRes;
//            setData(goodsDetailsRes.getContent());
//        }
//    }

    private void setData(GetDistributionGoodsDetailsData detailsData) {
        if (detailsData == null) {
            return;
        }
        if (detailsData.getGoodsInfo() != null) {
            viewBinding.tvGoodsName.setText(detailsData.getGoodsInfo().getProductName());
            viewBinding.tvBarCode.setText(detailsData.getGoodsInfo().getBarCode());
            viewBinding.tvCommodityCode.setText(detailsData.getGoodsInfo().getProductCode());
            viewBinding.tvSpecificationOfGoods.setText(detailsData.getGoodsInfo().getSpecification());
        }

        if (detailsData.getDistributionInfo() != null) {
            DistributionSlipInfo distributionSlipInfo = detailsData.getDistributionInfo();
            filedInfos.add(new GoodsFiledInfo("门店名称", distributionSlipInfo.getSalesroomName()));
            filedInfos.add(new GoodsFiledInfo("订单性质", distributionSlipInfo.getNatureOforder()));
            filedInfos.add(new GoodsFiledInfo("配送类型", distributionSlipInfo.getDistributionModel()));
            filedInfos.add(new GoodsFiledInfo("配送仓库", distributionSlipInfo.getWarehouseName()));
            filedInfos.add(new GoodsFiledInfo("订单总数", StringUtils.getCommaFormat(new BigDecimal(distributionSlipInfo.getOrderNum()))));
            filedInfos.add(new GoodsFiledInfo("配送总数", StringUtils.getCommaFormat(new BigDecimal(distributionSlipInfo.getDistributionNum()))));
            filedInfos.add(new GoodsFiledInfo("差异总数", StringUtils.getCommaFormat(new BigDecimal(distributionSlipInfo.getTotalDifferentNum()))));
            filedInfos.add(new GoodsFiledInfo("差异进价金额", StringUtils.getCommaFormat(BigDecimal.valueOf(distributionSlipInfo.getDifferentPurchasePrice())) + "元"));
            filedInfos.add(new GoodsFiledInfo("差异零售价金额", StringUtils.getCommaFormat(BigDecimal.valueOf(distributionSlipInfo.getDifferentRetailPrice())) + "元"));
            filedInfos.add(new GoodsFiledInfo("配送满足率", StringUtils.getCommaFormat(BigDecimal.valueOf(distributionSlipInfo.getDistributionGoodPercent() * 100)) + "%"));
            filedInfos.add(new GoodsFiledInfo("备注", distributionSlipInfo.getRemark()));
        }
        adapter.setList(filedInfos);
    }
}
